
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _babelHelperVueJsxMergeProps = _interopRequireDefault(require('@vue/babel-helper-vue-jsx-merge-props'));

const _utils = require('../utils');

const _functional = require('../utils/functional');

const _info = _interopRequireDefault(require('../info'));

// Utils
// Components
const _createNamespace = (0, _utils.createNamespace)('icon');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];

function isImage(name) {
  return name ? name.indexOf('/') !== -1 : false;
} // compatible with legacy usage, should be removed in next major version


const LEGACY_MAP = {
  medel: 'medal',
  'medel-o': 'medal-o',
};

function correctName(name) {
  return name && LEGACY_MAP[name] || name;
}

function Icon(h, props, slots, ctx) {
  const name = correctName(props.name);
  const imageIcon = isImage(name);
  return h(props.tag, (0, _babelHelperVueJsxMergeProps.default)([{
    class: [props.classPrefix, imageIcon ? '' : `${props.classPrefix}-${name}`],
    style: {
      color: props.color,
      fontSize: (0, _utils.addUnit)(props.size),
    },
  }, (0, _functional.inherit)(ctx, true)]), [slots.default && slots.default(), imageIcon && h('img', {
    class: bem('image'),
    attrs: {
      src: name,
    },
  }), h(_info.default, {
    attrs: {
      dot: props.dot,
      info: (0, _utils.isDef)(props.badge) ? props.badge : props.info,
    },
  })]);
}

Icon.props = {
  dot: Boolean,
  name: String,
  size: [Number, String],
  // @deprecated
  // should be removed in next major version
  info: [Number, String],
  badge: [Number, String],
  color: String,
  tag: {
    type: String,
    default: 'i',
  },
  classPrefix: {
    type: String,
    default: bem(),
  },
};

const _default = createComponent(Icon);

exports.default = _default;
